package cn.iborder.utils;

import com.jfinal.log.Log;

public class TrcLog {
	private static Log log = null;

	private TrcLog() {}
	
	public static Log getLogFile() {
		String clazz = getInvoke();
		if (log == null) {
			log = Log.getLog(clazz);
		}
		//log.info("[TrcLog]"+clazz);
		return log;
	}
	
	/**
	 * 获取调用方的class
	 * @return
	 */
	private static String getInvoke() {
        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
        StackTraceElement log = stackTrace[1];
        String tag = null;
        for (int i = 1; i < stackTrace.length; i++) {
            StackTraceElement e = stackTrace[i];
            if (!e.getClassName().equals(log.getClassName())) {
                tag = e.getClassName();
                break;
            }
        }
        if (tag == null) {
            tag = log.getClassName();
        }
        int index = tag.lastIndexOf(".");
        return tag.substring(index+1)+".class";
    }

}
